package com.caldremch.androidfoundation;

import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.caldremch.androidfoundation.base.BaseActivity;
import com.caldremch.androidfoundation.http.ApiObserver;
import com.caldremch.androidfoundation.http.BaseObserver;
import com.caldremch.androidfoundation.http.BaseReqData;
import com.caldremch.androidfoundation.http.RetrofitHelper;
import com.caldremch.androidfoundation.http.XHttp;
import com.caldremch.androidfoundation.http.callback.AbsCallback;
import com.caldremch.androidfoundation.http.model.BaseRespData;
import com.caldremch.androidfoundation.http.model.CommonConfigResp;

import butterknife.BindView;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * 主界面
 */
public class MainActivity extends BaseActivity {

    @BindView(R.id.tv)
    TextView mtextView;

    static String sStr;

    public static final String AA = "sdsd";


    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        mtextView.setText("high");
        mtextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

//                if (true) {
//
//
//                    XHttp.post("Common/Config.json").setJson("").
//                            request(new AbsCallback<CommonConfigResp>() {
//                                @Override
//                                public void onSuccess(BaseRespData<CommonConfigResp> respData, CommonConfigResp data) throws Exception {
//
//                                }
//
//                                @Override
//                                public void onFailure(BaseRespData<CommonConfigResp> respData, Throwable e) throws Exception {
//
//                                }
//                            });
//
//                    return;
//                }


                ApiObserver<CommonConfigResp> ob = new ApiObserver<CommonConfigResp>(new AbsCallback<CommonConfigResp>() {
                    @Override
                    public void onSuccess(BaseRespData<CommonConfigResp> respData, CommonConfigResp data) throws Exception {
                        Log.e("caldremch", "name = " + data.companyName);
                    }

                    @Override
                    public void onFailure(BaseRespData<CommonConfigResp> respData, Throwable e) throws Exception {

                    }
                });

                RetrofitHelper.getsApiService().getCommConfig(new BaseReqData())
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(ob);
            }
        });
    }

    @Override
    protected void initData() {

    }
}
